﻿@using Abp.Extensions
@using FutureGoodsMould = FutureApp.Shop.GoodsMould
@model FutureApp.Web.Models.Shop.GoodsMouldiewModel

@section Scripts{
    <script>
        !function ($) {
            var $$$ = function () {
                this.$box = $('.box');
                this.$form = $('form');
                this.service = abp.services.app.goodsMould;
                this.localize = abp.localization.localize;
            };
            $$$.prototype = {
                init: function () {
                    this.formSubmit();
                    this.binding();
                },
                formSubmit: function () {
                    this.$form.submit(function (e) {
                        e.preventDefault();
                    });
                },
                binding: function () {
                    var self = this;
                    self.$box.on("click", '.btn', function (e) {
                        e.preventDefault();

                        var $sender = $(e.currentTarget);
                        var action = $.trim($sender.data("action"));
                        switch (action) {
                            case "submit":
                                self.submit();
                                break;
                        }
                    });
                },
                submit: function () {
                    var self = this;
                    abp.ui.setBusy(self.$box);
                    var data = self.$form.serializeFormToObject();
                    self.service.createGoodsMould(data)
                        .done(function () {
                            abp.message.success(self.localize("AddGoodsMouldSucceed"))
                                .done(function () { location.href = "@Url.Action("list")"; });
                        })
                        .always(function () {
                            abp.ui.clearBusy(self.$box);
                        });
                }
            };

            $(function () { (new $$$()).init(); });
        }(jQuery);
    </script>
}
<ul class="content-nav">
    <li>
        <a href="@Url.Action("list")">@L("List")</a>
    </li>
    <li class="active">
        <a href="javascript:;">@L("Add")</a>
    </li>
</ul>
<div class="box box-success box-edge-all" data-dock="true">
    <form role="form" class="col-xs-10">
        <div class="box-body">
            <div class="form-group">
                <label>@L("GoodsMouldName")</label>
                <input name="Name" type="text" class="form-control" maxlength="@FutureGoodsMould.MaxNameLength" autofocus>
            </div>
            <div class="form-group">
                <label>@L("GoodsMouldAssembles")</label>
                <table data-toggle="table" data-key-events="true">
                    <thead>
                        <tr>
                            <th data-width="36"></th>
                            <th>@L("GoodsAttributeName")</th>
                            <th>@L("GoodsAttributeValues")</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var attr in this.Model.GoodsAttributes)
                        {
                            <tr data-attrid="@attr.Id">
                                <td class="bs-checkbox"><input name="GoodsAttributes[]" type="checkbox" value="@attr.Id"></td>
                                <td>@attr.Name</td>
                                <td>@string.Join("，", attr.Values.Select(v => v.Value)).TruncateWithPostfix(100)</td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
        <div class="box-footer">
            <a class="btn btn-primary" href="javascript:;" data-action="submit">
                <i class="fa fa-check"></i>
                @L("Submit")
            </a>
        </div>
    </form>
</div>